//
//  PushTieZiViewController.m
//  Liuhe
//
//  Created by zr on 2018/8/7.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "PushTieZiViewController.h"
#import "TieZiTableViewCell.h"
#import "TieZiInfoViewController.h"
#import "WeiteTieZiViewController.h"
#import "ClubModel.h"

@interface PushTieZiViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak)UITableView * tableView;
@property (nonatomic, strong)NSArray<ClubModel *> * modelListArray;

@end

@implementation PushTieZiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view .backgroundColor = WHITE_COLOR;
    
    [ClubModel clubModelWithType:@"32" WithSucess:^(NSArray<ClubModel *> *array) {
        
        self.modelListArray = array;
    } error:^{
        
    }];
    
    [self setupNav];
    [self setupUI];
}

- (void)setModelListArray:(NSArray<ClubModel *> *)modelListArray{
    
    _modelListArray = modelListArray;
    
    [self.tableView reloadData];
}


- (void)setupNav{
  
    UIButton * backButton1 = [[UIButton alloc] init];
    
//        backButton.frame = CGRectMake(0 , 0 , 22 * SCREENH6, 22 * SCREENH6);
//    [backButton1 setTitle:@"取消" forState:UIControlStateNormal];
    [backButton1 setImage:ImageNamed(@"bj") forState:UIControlStateNormal];
    
    [backButton1 addTarget:self action:@selector(ClickPushJobNeed) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * nextButton = [[UIBarButtonItem alloc] initWithCustomView:backButton1];
    
    self.navigationItem.rightBarButtonItem = nextButton;
    
}


- (void)setupUI{
    
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor whiteColor];
    tableView.rowHeight = 329 * SCREENH6;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView = tableView;
    
    [self.tableView registerClass:[TieZiTableViewCell class] forCellReuseIdentifier:@"TieZiListCell"];
    
    [self.view addSubview:self.tableView];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.modelListArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    TieZiTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TieZiListCell" forIndexPath:indexPath];

    cell.model = self.modelListArray[indexPath.row];
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HIDDEN_TAB;
    
    TieZiInfoViewController * infoVC = [TieZiInfoViewController new];
    
    ClubModel * model = self.modelListArray[indexPath.row];
    
    infoVC.ID = model.ID;
    
    [self.navigationController pushViewController:infoVC animated:YES];
    
    SHOW_TAB;
}


- (void)ClickPushJobNeed{
    
    HIDDEN_TAB;
    
    WeiteTieZiViewController * pushVC = [WeiteTieZiViewController new];
    
    pushVC.type = @"32";
    
    [self.navigationController pushViewController:pushVC animated:YES];
    
    SHOW_TAB;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
